package com.epoint.netty.rpc.client;

import com.epoint.netty.rpc.common.RpcRequestMessage;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class FeignProxy implements InvocationHandler {

    private Class interfaceClass;

    public <T> T getProxy(Class<T> interfaceClass) {
        this.interfaceClass = interfaceClass;

        Class<?>[] interfaces = new Class[]{interfaceClass};
        Object o = Proxy.newProxyInstance(FeignProxy.class.getClassLoader(),
                interfaces, this);
        return (T) o;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        RpcRequestMessage msg = new RpcRequestMessage(1, interfaceClass.getName(),
                method.getName(), method.getReturnType(), method.getParameterTypes(), args);
        System.out.println("我tm不管，我反正我发消息了 ");
//        Client_V2.getChannel().writeAndFlush(msg);
        Channel channel = Client_V2.getChannel();
        return null;
    }
}
